﻿using Domain.Flow;
using MediatR;
using U.B.ErrorCode;
using U.B.Repistory;
using U.B.WriteApi.Command.RabbitBWss;

namespace U.B.WriteApi.CommandHander.RabbitBWDD
{
    public class DelrabbitsCommandHander : IRequestHandler<DelrabbitsCommand, ApiResult<int>>
    {
        public readonly IRepistory<Product> _productRepistory;
        public DelrabbitsCommandHander(IRepistory<Product> productRepistory)
        {
            _productRepistory = productRepistory;
        }
        /// <summary>
        /// 商品删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<ApiResult<int>> Handle(DelrabbitsCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            var list = _productRepistory.GetAll().FirstOrDefault(x => x.ProductId == request.ProductId);
            _productRepistory.Delete(list);
            result.code = Renum.删除成功;
            result.Message=Renum.删除成功.ToString();
            return Task.FromResult(result);
        }
    }
}
